package com.example.goods_manage.controller;

import com.example.goods_manage.dto.Goods;
import com.example.goods_manage.dto.GoodsUpdateRequest;
import com.example.goods_manage.dto.request.GoodsInsertRequest;
import com.example.goods_manage.dto.request.GoodsRequest;
import com.example.goods_manage.service.GoodsService;
import com.example.goods_manage.utils.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <P> @Author: SongKeCheng
 * <P> Type: Class
 * <P> Description:
 * <P> Date: 2024/12/20:15:12
 */

@SuppressWarnings({"unchecked", ""})
@RestController
@RequestMapping("goods")
public class GoodsController {
    private static final Logger log = LoggerFactory.getLogger(GoodsController.class);

    @Autowired
    private GoodsService goodsService;

    /**
     * 根据商品名、作者名称 分页查询 商品数据
    */
    @GetMapping("/findGoods")
    public AjaxResult findGoods(GoodsRequest goodsRequest) {
        return goodsService.findGoods(goodsRequest);
    }

    /**
     * 新增商品数据
    */
    @PostMapping("/addGoods")
    public AjaxResult addGoods(@RequestBody GoodsInsertRequest insertRequest){
        return goodsService.addGoods(insertRequest);
    }

    /**
     * 根据id 查询商品数据
    */
    @GetMapping("/findById")
    public AjaxResult findById(GoodsRequest goodsRequest){
        return goodsService.findById(goodsRequest);
    }

    /**
     * 根据id 更新商品数据
    */
    @PostMapping("/updateGoods")
    public AjaxResult updateGoods(@RequestBody GoodsUpdateRequest goodsUpdateRequest){
        return goodsService.updateGoods(goodsUpdateRequest);
    }
}
